/**
 * 曾雪松
 * 24.12.25
 */
package org.qengine.controller;

import org.qengine.dao.StuInfoDao;
import org.qengine.entity.StuInfoEntity;
import org.qengine.service.PaperInfoService;
import org.qengine.service.StuInfoService;
import org.qengine.vo.StuInfoAnlysVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.List;


@RestController
@RequestMapping("/stuInfo")
public class StuInfoController {

    @Autowired
    private StuInfoService stuInfoService;

    @Autowired
    private PaperInfoService paperInfoService;


    @GetMapping("/{stuID}/papers")
    public List<Long> getPaperIDsByStuID(@PathVariable Long stuID) {
        List<Long> paperIDs =  stuInfoService.getStuPaperIDs(stuID);
        return paperIDs;
    }


    @RequestMapping("/{stuID}")
    public StuInfoEntity getStuInfo(@PathVariable Long stuID) {
        return stuInfoService.getStuInfo(stuID);
    }


    @PostMapping("/updateStuInfo")
    public ResponseEntity<StuInfoEntity> insertStuInfo(@RequestBody StuInfoEntity stuInfoEntity) {
        StuInfoEntity insertedStuInfo = stuInfoService.updateStuInfo(stuInfoEntity);
        return ResponseEntity.status(HttpStatus.CREATED).body(insertedStuInfo);
    }


    @RequestMapping("/deleteStuInfo")
    public String deleteStuInfo(@RequestParam("stuID") Long stuID) {
        int result =  stuInfoService.deleteStuInfo(stuID);
        if(result >= 1) {
            return "删除成功";
        } else {
            return "删除失败";
        }
    }


    @RequestMapping("/getAllStuInfo")
    public List<StuInfoEntity> getAllStuInfo() {
        return stuInfoService.getAllStuInfo();
    }


    // 根据学生姓名进行模糊查询
    @GetMapping("/searchByName")
    public List<StuInfoEntity> searchStuInfoByName(@RequestParam("name") String stuName) {
        return stuInfoService.getStuInfoByStuName(stuName);
    }

    // 根据学生姓名和学号进行模糊查询
    @GetMapping("/searchByNameAndID")
    public List<StuInfoEntity> searchStuInfoByNameAndID(@RequestParam("name") String stuName, @RequestParam("id") Long stuID) {
        return stuInfoService.getStuInfoByStuNameAndStuID(stuName, stuID);
    }


}


